package com.yuexunit.finance.project.action.v1;

import java.util.HashMap;

import org.json.JSONObject;

import com.baidu.aip.ocr.AipOcr;
import com.yuexunit.fs.service.TransferService;
import com.yuexunit.inject.ComponentFactory;

/**
 *@version 创建时间：2017年12月11日 上午9:45:38
 *@author wenwenlong
 *类说明
 */

public class ImageRecognitionApiImpl implements ImageRecognitionApi {
	//设置APPID/AK/SK
	private static final String APP_ID = "10380090";
	private static final String API_KEY = "2cpVWdwrlGhVRO6wAU6GTc6o";
	private static final String SECRET_KEY = "GV1cNQ4jXmZ3dXs1HuqdmpPb0vB8xhEQ";

	private TransferService transferService = ComponentFactory.loadClass(TransferService.class);

	public void createBailReturn(Integer type, String fileUuid) {
		// 初始化一个AipOcr
		AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
		// 可选：设置网络连接参数
		client.setConnectionTimeoutInMillis(2000);
		client.setSocketTimeoutInMillis(60000);

		// 可选：设置代理服务器地址, http和socket二选一，或者均不设置
		//   client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
		// client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

		//		FileEntry fe = transferService.inquireFileEntry(fileUuid);
		//		String filePath = ConfigPropertites.getProperties("UPLOAD_FILE_PATH") + fe.getUri(); //文件地址
		String filePath = "c:/Users/NTBK-021-1006/Pictures/123.jpg";
		//		JSONObject res = client.basicGeneral(filePath, new HashMap<String, String>());	

		HashMap<String, String> options = new HashMap<String, String>();

		switch (type) {
		case 1://身份证正面
			// 设置识别身份证正面参数
			boolean isFront = true;
			JSONObject response = client.idcard(filePath, isFront, options);
			System.out.println(response.toString());
			break;
		case 2://车牌识别
			// 参数为本地图片路径
			response = client.plateLicense(filePath);
			System.out.println(response.toString());
			break;
		case 3:// 通用文字识别高精度版（含位置信息版） 
			response = client.accurateGeneral(filePath,options);
			System.out.println(response.toString());
			break;
		case 4://银行卡识别
			response = client.bankcard(filePath);
			System.out.println(response.toString());
			break;
		case 5://通用票据识别  用户向服务请求识别医疗票据、发票、的士票、保险保单等票据类图片中的所有文字，并返回文字在图中的位置信息。
			response = client.receipt(filePath, options);
			System.out.println(response.toString());
			break;
		case 6://营业执照识别
			response = client.businessLicense(filePath, null);
			System.out.println(response.toString());
			break;
		case 7: //驾驶证识别
			response = client.drivingLicense(filePath, options);
			System.out.println(response.toString());
			break;
		case 8://行驶证识别
			response = client.vehicleLicense(filePath, options);
			System.out.println(response.toString());
			break;
		case 9:

			break;
		case 10:

			break;
		case 11:

			break;
		default:
			break;
		}
	}

	public static void main(String[] args) {
		// 初始化一个AipOcr
		AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
		// 可选：设置网络连接参数
		client.setConnectionTimeoutInMillis(2000);
		client.setSocketTimeoutInMillis(60000);

		// 可选：设置代理服务器地址, http和socket二选一，或者均不设置
		//   client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
		// client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

		//				FileEntry fe = transferService.inquireFileEntry(fileUuid);
		//				String filePath = ConfigPropertites.getProperties("UPLOAD_FILE_PATH") + fe.getUri(); //文件地址
		String filePath = "C:\\Users\\NTBK-021-1006\\Pictures\\123.jpg";
		//				JSONObject res = client.basicGeneral(filePath, new HashMap<String, String>());	

		HashMap<String, String> options = new HashMap<String, String>();
		Integer type = 6;
		switch (type) {
		case 1://身份证正面
			// 设置识别身份证正面参数
			boolean isFront = true;
			JSONObject response = client.idcard(filePath, isFront, options);
			System.out.println(response.toString());
			break;
		case 2://车牌识别
			// 参数为本地图片路径
			response = client.plateLicense(filePath);
			System.out.println(response.toString());
			break;
		case 3:// 通用文字识别高精度版（含位置信息版） 
			response = client.accurateGeneral(filePath,options);
			System.out.println(response.toString());
			break;
		case 4://银行卡识别
			response = client.bankcard(filePath);
			System.out.println(response.toString());
			break;
		case 5://通用票据识别  用户向服务请求识别医疗票据、发票、的士票、保险保单等票据类图片中的所有文字，并返回文字在图中的位置信息。
			response = client.receipt(filePath, options);
			System.out.println(response.toString());
			break;
		case 6://营业执照识别
			response = client.businessLicense(filePath, null);
			System.out.println(response.toString());
			break;
		case 7: //驾驶证识别
			response = client.drivingLicense(filePath, options);
			System.out.println(response.toString());
			break;
		case 8://行驶证识别
			response = client.vehicleLicense(filePath, options);
			System.out.println(response.toString());
			break;
		case 9:

			break;
		case 10:

			break;
		case 11:

			break;
		default:
			break;
		}
	}
}
